import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class FlowerpotS {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int MAXN = 100001;
    public static int[][] arr = new int[MAXN][2];
    public static int[] maxDeque = new int[MAXN]; // 存储下标
    public static int[] minDeque = new int[MAXN]; // 存储下标
    public static int n,d,hMin,tMin,hMax,tMax,ans;
    public static void main(String[] args) throws IOException {
        n = in.nextInt();
        d = in.nextInt();
        hMin = tMin = hMax = tMax = 0;
        ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            arr[i][0] = in.nextInt(); // x 轴位置
            arr[i][1] = in.nextInt(); // 高度
        }
        // 按照 x 轴进行排序操作
        Arrays.sort(arr,0,n,(a,b) -> {
            return a[0] - b[0];
        });
        int l = 0;
        for (int r = 0; r < n; r++) {
            // 维护最大高度的单调队列
            while (hMax < tMax && arr[maxDeque[tMax - 1]][1] <= arr[r][1]) {
                tMax--;
            }
            maxDeque[tMax++] = r;
            // 维护最小高度的单调队列
            while (hMin < tMin && arr[minDeque[tMin - 1]][1] > arr[r][1]) {
                tMin--;
            }
            minDeque[tMin++] = r;
            // 如果大于等于的话, 就准备收缩左边的, 收缩只会使 d 变小或不变
            while (arr[maxDeque[hMax]][1] - arr[minDeque[hMin]][1] >= d) {
                // 每次进行一下对比
                ans = Math.min(ans,arr[r][0] - arr[l][0]);
                // 为头就 ++
                if (maxDeque[hMax] == l) {
                    hMax++;
                }
                if (minDeque[hMin] == l) {
                    hMin++;
                }
                l++;
            }
        }
        // 如果都没有符合的信息就返回 -1
        out.print(ans == Integer.MAX_VALUE ? -1 : ans);
        out.close();
    }




















    public static class Read {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }
}
